package com.springcloud.sc.ucpv5.client.application.message.type.shortType;

import java.nio.ByteBuffer;

import com.springcloud.sc.ucpv5.client.application.util.UnsignedNumberConvert;

/**
 * 有符号短整型
 * 
 */
public class Short_Wrap extends ShortWrapPublic {
    /**
     * 组包有符号短整型
     * 
     * @param buffer
     * @param value
     * @param key
     *            包含所有该类型所需的属性条件
     */
    public static byte[] packShort(int value, int length, boolean isOrder) {
	short tShort = UnsignedNumberConvert.getSignedShortInBytes(value);
	return packUnShortPublic(tShort, length, isOrder);
    }

    /**
     * 解包有符号短整型,从缓存里取出两个字节的数据，如果指定长度大于2，则抛弃多余长度的字节
     * 
     * @param buffer
     * @param key
     *            包含所有该类型所需的属性条件
     */
    public static int unpackShort_int(ByteBuffer buffer, int length, boolean isOrder) throws NullPointerException {
	ByteBuffer tempBuffer = unpackShortPublic(buffer, length, isOrder);
	// tempBuffer = makeByteOrder(tempBuffer, isOrder);
	int tInt = tempBuffer.getShort(0);

	return tInt;
    }

    /**
     * 解包有符号短整型,从缓存里取出两个字节的数据，如果指定长度大于2，则抛弃多余长度的字节
     * 
     * @param buffer
     * @param key
     *            包含所有该类型所需的属性条件
     */
    public static String unpackShort(ByteBuffer buffer, int length, boolean isOrder) throws NullPointerException {
	ByteBuffer tempBuffer = unpackShortPublic(buffer, length, isOrder);
	int tInt = tempBuffer.getShort(0);

	return String.valueOf(tInt);
    }

}
